<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>九大隐式对象之Request</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
    //1获得所有请求的名称
    Enumeration<String> headerNames=request.getHeaderNames();
    while(headerNames.hasMoreElements()){
    
      String headName=headerNames.nextElement();
      //获得每个请求，及其对应的值
      out.println(headName+"-->"+request.getHeader(headName)+"<br>");
      
    }
    out.println("<hr/>");
    
    //2设置解码方式，对于简体中文
    request.setCharacterEncoding("UTF-8");
    
    //3下边依次获得表单域的值
    String name=request.getParameter("name");
    String gender=request.getParameter("gender");
    //如果请求参数为多个值，将使用该方法获得
    String[] color=request.getParameterValues("color");
    String national=request.getParameter("country");
    
    
    //用于解析get方式中的非西欧字符（通过get方式的中文字符都要用ISO－8859-1编码的）
    byte[] nameBytes=name.getBytes("ISO-8859-1");
    name=new String(nameBytes,"UTF-8");
    
    
     %>
     
     <!-- 下边依次输出表单的值 -->
     
     您的名字：<%=name %><hr>
     您的性别：<%=gender %><hr>
     您喜欢的颜色：<% if(color!=null)for(String c :color){out.println(c+"");} %><hr>
     您来自的国家：<%=national%><hr>
     
    
  </body>
</html>
